# main.py
import os, sys
import openpyxl as pyxl

# 使用相对导入导入 pappertool 包中的 common_functions 模块
from papertools import common_functions

# 在这里可以使用 common_functions 模块中的函数

excelFile =  os.path.dirname(__file__) + "/dest/data_1.xlsx"
print(excelFile)
# 期望值和实际满意度值都来自 HT酒店问卷.xlsx(sheet-result)
#expectList = [4.7678,3.6186,4.2126,4.645,3.6186,4.2086,4.3846,4.2955,3.9666,4.0586,4.2747,4.5946,4.2701,3.9326,4.2927,4.4814,3.9269,4.5673,4.2785,3.8283,4.4761,4.4532,4.4108]

# perciveList = [2.5332,4.258,3.437,2.6852,4.1787,3.241,3.7591,3.6448,3.372,3.63,4.258,2.8037,3.9104,3.6703,3.8763,3.997,3.7745,3.1142,3.9463,3.6831,3.1383,3.2094,3.3453]
perciveList = [2.5332]


# 打开或创建工作簿
try:
    pyxlbg = pyxl.load_workbook(excelFile)
except FileNotFoundError:
    # 如果文件不存在，创建一个新的工作簿
    pyxlbg = pyxl.Workbook()

# 检查是否存在'perciveList'表，如果不存在，创建一个
if "perciveList" not in pyxlbg.sheetnames:
    pyxlbg.create_sheet("perciveList")


for colIndex in range(len(perciveList)):

    resultColum = common_functions.generateRandomNumsByExpectAverage(perciveList[colIndex]) 
    # xlsx文件的的perciveList表
    sheet = pyxlbg["perciveList"]                             		 
    for row in range(len(resultColum)):						
        sheet.cell(row+1 , colIndex + 1, resultColum[row])	# sheet.cell(1,1,num_list[0])表示将num_list列表的第0个数据1写入到excel对应表格的第一行第一列
    pyxlbg.save(excelFile)      